package com.zrrd.controller;


import com.zrrd.common.page.ImageClassPageVo;
import com.zrrd.common.util.ResponseResult;
import com.zrrd.entity.ImageClass;
import com.zrrd.service.ImageClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wanjl
 * @since 2024-09-12
 */
@Api(tags = "相册管理接口")
@RestController
@RequestMapping("/admin/imageClass")
@ResponseBody
public class ImageClassController {
    @Resource
    private ImageClassService imageClassService;


    /**
     * 分页查询所有
     * @return
     */
    @ApiOperation(value = "分页查询&搜索",notes = "分页查询&搜索详情介绍")
    @GetMapping("/{page}")
    public ResponseResult findByPage(@PathVariable("page") Integer page,
                                     @RequestParam(value = "limit",required = false,defaultValue = "10") Integer limit,
                                     @RequestParam(value = "keyword",required = false) String keyword){
        ImageClassPageVo imageClassPageVo=imageClassService.findByPage(page,limit,keyword);
        return ResponseResult.queryResponse(imageClassPageVo);
    }

    /**
     * 新增
     * @param imageClass
     * @return
     */
    @PostMapping()
    public ResponseResult add(@RequestBody ImageClass imageClass){    //如果参数是某个实体类，那么注意在参数类型前加@RequestBody注解
        return ResponseResult.saveResponse(imageClassService.save(imageClass));  //新增，把对象里的属性，新增到MySQL数据库
    }

    /**
     * 修改
     * @param imageClass
     * @return
     */
    @PutMapping
    public ResponseResult update(@RequestBody ImageClass imageClass){
        return ResponseResult.updateResponse(imageClassService.updateById(imageClass)); //修改，根据id修改数据库的内容
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}/delete")
    public ResponseResult delete(@PathVariable("id") Integer id){ //如果参数类型不是实体类，而是其他如整数等类型，那么添加@PathVariable 注解
        return ResponseResult.deleteResponse(imageClassService.removeById(id)); //删除，根据id删除数据库的数据
    }

}

